﻿package mortal.game.view.pack.other
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.firstReCharge.*;

    public class MulSelectCellRender extends GCellRenderer
    {
        private var _bg:GBitmap;
        private var _costBitmap:GBitmap;
        private var _getGiftBtn:GLoadingButton;
        private var _item:EffectItem;
        private var _costNum:BitmapNumberText;
        private var _arr:Array;
        private var _itemData:ItemData;

        public function MulSelectCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildren();
            this._bg = UIFactory.gBitmap("", 0, 0, null);
            this._costBitmap = UIFactory.gBitmap("", 0, 85, this);
            this._item = UICompomentPool.getUICompoment(EffectItem);
            this._item.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
            this._item.x = 10;
            this._item.y = 15;
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            this._item.showEffect(true, 36, 32, "ArriundEffect_cheng_big.swf");
            this.addChild(this._item);
            this._costNum = UIFactory.bitmapNumberText(10, 87, "MulSelectGiftNum.png", 19, 21, -9, this, 9, BitmapNumberText.Left);
            this._getGiftBtn = UIFactory.gLoadingButton(ResFileConst.MulSelcetBtn, 1, 108, 85, 29, this);
            this._getGiftBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._costBitmap.dispose(param1);
            this._costBitmap = null;
            this._getGiftBtn.dispose(param1);
            this._getGiftBtn = null;
            this._item.dispose(param1);
            this._item = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._costNum.dispose(param1);
            this._costNum = null;
            this._arr.length = 0;
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.mulSelectCellBg);
            if (this._arr[4] > 0)
            {
                this._costBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.mulSelectTxt2);
                this._costBitmap.x = this._costNum.x + (this._arr[4] as String).length * 11;
            }
            else
            {
                this._costBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.mulSelectTxt1);
                this._costBitmap.x = 10;
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            this._arr = (param1.data as String).split("#");
            this._itemData = param1.item as ItemData;
            this._item.itemData = new ItemData(int(this._arr[1]));
            this._item.amount = this._arr[2];
            this._costNum.text = this._arr[4] > 0 ? (this._arr[4]) : ("");
            LoaderHelp.addResCallBack(ResFileConst.mulSelectPackage, this.showSkin);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var enterAlert:Function;
            var e:* = event;
            enterAlert = function () : void
            {
                if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, int(_arr[4]), null, false))
                {
                    GameProxy.packProxy.useItem(_itemData.serverData.uid, _itemData.itemCode, 1, [int(_arr[3])]);
                    MulSelectPackageWin.instance.hide();
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(35469));
                }
                return;
            }// end function
            ;
            var str:* = Language.getStringByParam(35468, int(this._arr[4]), this._itemData.itemInfo.name);
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.MulSelectWin, enterAlert, str, null, Alert.OK | Alert.CANCEL);
            return;
        }// end function

    }
}
